package com.huqiwen.test;

public class Permutation {
	private char[] chars;
	int count = 0;
	char temp;
	public Permutation() {
		String str = "122345";
		chars = str.toCharArray();
		combination(chars,chars.length,0);	
	}

	public static void main(String[] args) {
		long begin = System.nanoTime();
		Permutation test = new Permutation();	
		System.out.println("执行时间:" + (System.nanoTime() - begin) + "纳秒");
		System.out.println(test.count);
	}

	public void combination(char[] arr,int length,int n) {
		if (length == n) {
			if (arr[2] != '4') {
				String str = new String(arr);
				if (str.indexOf("53") < 0 && str.indexOf("35") < 0) {
					System.out.println(str);
					++count;
				}
			}
		} else {
			for (int i = n; i < length; i++) {				
				swap(arr, n, i);
				combination(arr, length, n + 1);
				swap(arr, i, n);
			}
		}
	}
	private void swap(char[] a, int x, int y) {
		if (x!=y) {
			temp = a[x];
			a[x] = a[y];
			a[y] = temp;	
		}		
	}

}
